<?php

/**
 * CelebrioMail PeopleManagement
 *
 * @copyright  Copyright (c) 2011 Celebrio Software
 * @package    PeopleManagement
 */
namespace ApplicationsModule\PeopleModule;

use dibi;

use \Nette\ArrayTools;

/**
 * 
 * @author pavel
 */
class MailContact extends DummyContactService implements IContactService {

    const MAIL_SERVICE = "mail";
    const MAIL_ADDRESS = "mail_address";
    const MAIL_TYPE = "mail_type";

    static function getServiceName() {
        return self::MAIL_SERVICE;
    }

    static function providedRows(array $exclude = array()) {
        return array(
            array("db" => self::MAIL_ADDRESS, "display" => _("E-mail address"), "protected" => false, "unique" => true),
            array("db" => self::MAIL_TYPE, "display" => false, "protected" => false, "unique" => false),
        );
    }

    /**
     * @param int $personId
     * @return array All e-mail addresses related to the queried user. Empty array if there is no one.
     */
    public function getMail($personId) {
        $pm = new PeopleManagement();
        $info = $pm->getPerson($personId)->getAdditionalInfo();
        return ArrayTools::get($info, self::MAIL_ADDRESS, array());
    }
    
    public function getIdentifier($personId) {
        return $this->getMail($personId);
    }

    public function addPerson(Person $person, array $other_info = null) {
        $mail_contact = array("id_person" => $person->getId(), "mail_address" => $other_info["mail"]);
        dibi::insert("contacts_mail", $mail_contact)->execute();
    }


}